<template>
	<view class="douyin-video-container">
		<!-- 导航栏 -->
		<aitip-nav-top 
			:nav-opacity="1"
			:title="videoInfo.title || 'AI视频生成'"
			:show-collection-button="false"
			:show-share-button="true"
			@go-back="goBack"
			@share="shareVideo"
		></aitip-nav-top>

		<!-- 主视频容器 -->
		<view class="main-video-container">
			<video id="main-video" :src="currentVideoUrl" :muted="false" :loop="true" :autoplay="false"
				:controls="false" :enable-progress-gesture="false" object-fit="cover" class="fullscreen-video"
				@loadstart="onMainVideoLoadStart" @canplay="onMainVideoCanPlay" @play="onMainVideoPlay"
				@pause="onMainVideoPause" @ended="onMainVideoEnded" @error="onMainVideoError"
				@click="toggleVideoPlay"></video>
		</view>





		<!-- 右侧操作栏 -->
		<view class="right-sidebar">
			<!-- 生成视频按钮 -->
			<view class="generated-video-button" @click="toggleGeneratedVideo" v-if="hasGeneratedVideo">
				<view class="video-button-icon">
					<text class="video-icon">{{ isShowingGeneratedVideo ? '⟲' : '▶' }}</text>
				</view>
				<text class="video-button-text">{{ isShowingGeneratedVideo ? '素材视频' : '我的视频' }}</text>
			</view>


			<!-- 用户头像/上传照片 -->
			<view class="avatar-container" @click="uploadPhoto">
				<image :src="getCachedImageUrl()" mode="aspectFill" class="user-avatar"></image>
				<view class="avatar-border"></view>
				<view class="upload-plus">+</view>
			</view>
		</view>

		<!-- 底部视频信息区域 -->
		<view class="bottom-info">
			<!-- 视频标题和描述 -->
			<view class="video-info">
				<text class="video-title">{{ videoInfo.title }}</text>
				<text class="video-subtitle">{{ videoInfo.subtitle }}</text>
				<view class="video-meta">
					<text class="video-author">@{{ videoInfo.author || '驴小拍' }}</text>
					<text class="video-duration">{{ videoInfo.duration || '0:15' }}</text>
				</view>
			</view>

			<!-- 立即生成按钮 -->
			<view class="generate-button" @click="handleGenerateClick" :class="{ 'generating': isGenerating }">
				<text class="generate-text">{{ getGenerateButtonText() }}</text>
			</view>
		</view>

		<!-- 视频加载状态 -->
		<view v-if="isVideoLoading" class="video-loading-overlay">
			<view class="loading-spinner"></view>
			<text class="loading-text">视频加载中...</text>
		</view>

		<!-- 播放暂停提示 -->
		<!-- 播放暂停提示 -->
		<view v-if="!isPlaying && !isVideoLoading" class="play-pause-indicator" @click="toggleVideoPlay">
			<view class="play-icon-large">
				<image src="https://cdn.xryai.cn/picGo/20250909112431546.png" mode="aspectFit" class="play-icon-image">
				</image>
			</view>
		</view>

		<!-- 处理状态提示 -->
		<view v-if="loading" class="fusion-loading">
			<view class="loading-spinner"></view>
			<text class="status-text">{{ statusText }}</text>
		</view>

		<!-- 水印处理状态提示 -->
		<view v-if="showWatermarkProgress" class="watermark-loading">
			<view class="loading-spinner watermark-spinner"></view>
			<text class="status-text">{{ watermarkProgressText }}</text>
			<text class="watermark-tip">正在为您的视频添加专属水印</text>
		</view>

		<!-- 结果预览弹窗 -->
		<view class="result-modal" v-if="showResultModal" @click="closeResultModal">
			<view class="result-modal-content" @click.stop>
				<view class="result-modal-header">
					<text class="result-modal-title">AI视频生成结果</text>
				</view>
				<view class="result-modal-body">
					<video :src="resultVideoUrl" :controls="true" :show-fullscreen-btn="true"
						class="result-video"></video>
				</view>
				<view class="result-modal-footer">
					<button class="share-btn" open-type="share" @click="shareVideo">分享</button>
					<button class="close-btn" @click="closeResultModal">关闭</button>
				</view>
			</view>
		</view>

		<!-- 我为村BA代言弹窗 -->
		<view class="village-ba-modal-overlay" v-if="showVillageBAModal" @click="closeVillageBAModal">
			<view class="village-ba-modal-content" @click.stop>
				<!-- 活动图片 -->
				<view class="village-ba-image-container">
					<image :src="villageBAImagePath" mode="aspectFill" class="village-ba-image"
						@error="onVillageBAImageError" @load="onVillageBAImageLoad" v-if="!villageBAImageLoadFailed">
					</image>
					<!-- 图片加载失败时的备用显示 -->
					<view v-if="villageBAImageLoadFailed" class="village-ba-placeholder">
						<text class="placeholder-text">我为村BA代言</text>
					</view>

					<!-- 支付代言按钮 -->
					<view class="village-ba-buttons-group">
						<view class="village-ba-button endorsement-button" @click="endorseVillageBA">
							<text class="village-ba-text">
								<text class="highlight-text">9.9元</text> 我为村BA代言 <text class="highlight-text">赢大奖</text>
							</text>
						</view>
					</view>

					<!-- 关闭按钮 -->
					<view class="village-ba-close-button" @click="closeVillageBAModal">
						<text class="village-ba-close-text">×</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 奖励二维码弹窗 -->
		<view class="reward-dialog" v-if="showRewardDialog">
			<view class="dialog-mask" @click="closeRewardDialog"></view>
			<view class="dialog-content reward-content">
				<view class="dialog-title">恭喜获得礼物兑换券！</view>
				<view class="qrcode-container">
					<image :src="qrcodeImage" mode="aspectFit" class="qrcode-image"></image>
				</view>
				<view class="coupon-info">
					<view class="coupon-code">兑换券编号：{{ couponCode }}</view>
					<view class="coupon-expire">有效期至：{{ expireDate }}</view>
					<view class="coupon-desc">请到线下门店出示此二维码进行核销</view>
				</view>
				<view class="dialog-buttons">
					<button class="save-btn" @click="saveQrcode">保存到相册</button>
					<button class="close-btn" @click="closeRewardDialog">我知道了</button>
				</view>
			</view>
		</view>

		<!-- 保存成功提示 -->
		<view class="save-success" v-if="showSaveSuccess">
			<view class="success-content">
				<text class="iconfont icon-ic_complete1"></text>
				<text class="success-text">已保存到相册</text>
			</view>
		</view>




	</view>
</template>

<script>
// 导入小程序专用视频缓存服务
import MiniProgramVideoCache from '@/api/ai-trip/miniProgramVideoCacheService.js';
import { chooseAndUploadImage } from '@/api/ai-trip/uploadService.js'
import { submitVideoFusion, getVideoFusionStatus } from '@/api/ai-trip/videoFusionService.js'
import videoWatermarkService from '@/api/ai-trip/videoWatermarkService.js'
import aitipNavTop from '@/components/aitipNavTop/index.vue'

export default {
	components: {
		aitipNavTop
	},
	data() {
		return {
			// 当前模板信息
			templateId: null,
			templateTitle: '',
			templateVideoUrl: '',
			originalVideoUrl: '', // 原始视频URL
			lowQualityVideoUrl: '', // 低质量视频URL

			// 主视频信息
			currentVideoUrl: 'https://cdn.zhzfpn.cn/video-test.mp4', // 默认视频
			posterImage: '',
			videoInfo: {
				title: 'AI视频合成',
				subtitle: '上传照片，生成专属AI视频'
			},

			// 视频播放状态
			isPlaying: false,
			isVideoLoading: false,
			videoContext: null,

			// 用户照片
			uploadedImageUrl: '', // 用户上传图片的URL
			defaultAvatar: 'https://ybpark.oss-cn-beijing.aliyuncs.com/2207191635365062413/2025/7/1/1/a82177b50505f7ef2ebd1120ced2cd29.jpg',

			// 生成状态
			isGenerating: false,
			showResultModal: false,
			resultVideoUrl: '',

			// 小程序专用视频缓存管理器
			videoCache: null,

			// 小程序网络状态
			networkType: 'unknown',
			isWifiConnected: false,
			modelId: '', // 模板ID
			jobId: '', // 视频融合任务ID
			videoUrl: '', // 融合后视频URL
			loading: false,
			pollingTimer: null,
			statusText: '',
			isDownloading: false,
			videoUrlCache: {}, // 用于缓存不同模板的视频URL

			// 抖音式交互相关
			autoPlayEnabled: true, // 是否启用自动播放
			hasAutoPlayed: false, // 是否已经自动播放过
			touchStartY: 0, // 触摸开始Y坐标
			touchStartTime: 0, // 触摸开始时间
			isScrolling: false, // 是否正在滚动
			scrollThreshold: 50, // 滑动阈值（像素）

			// 视频预加载和缓存
			videoPreloader: null, // 视频预加载器
			videoCacheQueue: [], // 视频缓存队列
			maxCacheSize: 3, // 最大缓存数量

			// 生成视频相关
			hasGeneratedVideo: false, // 是否有生成的视频
			isShowingGeneratedVideo: false, // 当前是否显示生成的视频
			originalVideoUrl: '', // 原始模板视频URL
			generatedVideoUrl: '', // 生成的视频URL

			// 村BA代言弹窗相关
			showVillageBAModal: false, // 是否显示村BA代言弹窗
			villageBAImagePath: '/static/images/village-ba.png', // 村BA活动图片路径
			villageBAImageLoadFailed: false, // 村BA图片是否加载失败
			hasEndorsed: false, // 是否已代言

			// 图片缓存相关
			imageCacheKey: 'user_uploaded_image_cache', // 图片缓存key
			defaultImageUrl: '/static/images/tabbar/kefu.png', // 默认图片路径

			// 视频加载状态
			isLoadingVideo: false, // 是否正在加载视频

			// 添加礼品兑换券相关数据
			showRewardDialog: false, // 是否显示奖励二维码弹窗
			qrcodeImage: 'https://cdn.zhzfpn.cn/PicGo/20250903113454004.png', // 二维码图片链接
			couponCode: 'GIFT' + Math.floor(100000 + Math.random() * 900000), // 随机兑换券编号
			expireDate: '2025-12-31', // 兑换券有效期
			showSaveSuccess: false, // 控制保存成功提示显示

			// 水印相关状态
			isAddingWatermark: false, // 是否正在添加水印
			watermarkJobId: '', // 水印任务ID
			watermarkedVideoUrl: '', // 带水印的视频URL
			showWatermarkProgress: false, // 是否显示水印进度
			watermarkProgressText: '正在添加水印...' // 水印进度文本
		}
	},

	async onLoad(options) {
		console.log('[AI视频详情] onLoad options:', options)
		try {
			// 获取从模板选择页传递的参数
			if (options.templateId) {
				this.templateId = parseInt(options.templateId);
				this.templateTitle = decodeURIComponent(options.title || '');
				this.templateVideoUrl = decodeURIComponent(options.videoUrl || '');

				// 获取更多参数
				this.videoInfo = {
					title: this.templateTitle || 'AI视频合成',
					subtitle: '上传照片，与模板合成专属视频',
					duration: decodeURIComponent(options.duration || '0:15'),
					author: decodeURIComponent(options.author || '驴小拍')
				};

				// 使用传递的视频URL
				if (this.templateVideoUrl) {
					this.currentVideoUrl = this.templateVideoUrl;
					this.originalVideoUrl = this.templateVideoUrl; // 保存原始视频URL
					console.log('[AI视频详情] 设置视频URL:', this.currentVideoUrl);
				}

				// 存储原始URL和低质量URL，用于网络切换
				if (options.originalUrl) {
					this.originalVideoUrl = decodeURIComponent(options.originalUrl);
				}
				if (options.lowQualityUrl) {
					this.lowQualityVideoUrl = decodeURIComponent(options.lowQualityUrl);
				}

				console.log('[AI视频详情] 使用模板:', {
					id: this.templateId,
					title: this.templateTitle,
					videoUrl: this.templateVideoUrl,
					originalUrl: this.originalVideoUrl,
					lowQualityUrl: this.lowQualityVideoUrl
				});
			} else {
				console.log('[AI视频详情] 使用默认配置');
			}

			if (options.modelId) {
				this.modelId = options.modelId
				console.log('[AI视频详情] onLoad 获取到 modelId:', this.modelId)
			} else if (options.modelid) {
				this.modelId = options.modelid
				console.log('[AI视频详情] onLoad 获取到 modelid:', this.modelId)
			} else {
				console.warn('[AI视频详情] onLoad 未获取到 modelId，options:', options)
			}

			// 先检测网络状态
			await this.detectNetworkStatus();

			// 初始化小程序专用视频缓存服务（只在有网络时）
			if (this.networkType !== 'none') {
				try {
					this.videoCache = new MiniProgramVideoCache();
					await this.videoCache.init();
					console.log('[AI视频详情] 视频缓存服务初始化成功');
				} catch (cacheError) {
					console.warn('[AI视频详情] 视频缓存服务初始化失败:', cacheError);
					// 创建一个空的缓存对象
					this.videoCache = {
						cache: async () => null,
						init: async () => { },
						clear: async () => { }
					};
				}
			} else {
				// 无网络时创建空缓存对象
				this.videoCache = {
					cache: async () => null,
					init: async () => { },
					clear: async () => { }
				};
			}

			// 初始化视频播放器
			this.$nextTick(() => {
				this.initVideoPlayer();
			});

			// 从缓存中获取上传的图片
			this.loadUploadedImageFromCache();

			// 检查是否有缓存的生成视频
			this.checkCachedGeneratedVideo();

			// 设置村BA活动图片路径
			this.setVillageBAImagePath();

			// 延迟自动播放视频
			setTimeout(() => {
				this.startAutoPlay();
			}, 1000); // 延迟1秒，确保页面和视频都已加载

		} catch (error) {
			console.error('[AI视频详情] 页面初始化失败:', error);
			uni.showToast({
				title: '页面初始化失败',
				icon: 'error',
				duration: 3000
			});
		}
	},

	onUnload() {
		// 清理视频播放器
		if (this.videoContext) {
			this.videoContext.stop();
		}

		// 清理网络监听
		uni.offNetworkStatusChange();

		// 清理内存监听
		if (uni.offMemoryWarning) {
			uni.offMemoryWarning();
		}
		if (this.pollingTimer) clearInterval(this.pollingTimer)

		// 清除分享标记
		uni.removeStorageSync('videoShared');
	},

	onHide() {
		// 页面隐藏时暂停视频
		if (this.videoContext && this.isPlaying) {
			this.videoContext.pause();
		}
	},

	onShow() {
		console.log('页面显示');

		// 检查是否有分享成功的标记
		const hasShared = uni.getStorageSync('videoShared');
		console.log('videoShared 标记:', hasShared);

		if (hasShared) {
			// 清除标记
			uni.removeStorageSync('videoShared');

			// 显示奖励弹窗
			setTimeout(() => {
				this.showRewardDialog = true;
				console.log('显示奖励弹窗');
			}, 500); // 延迟显示，确保用户能看到
		}
	},

	methods: {
		goBack() {
			// 停止视频播放
			if (this.videoContext) {
				this.videoContext.stop();
			}
			uni.navigateBack();
		},

		/**
		 * 处理分享按钮点击
		 */
		handleShareClick() {
			// 检查是否有生成的视频
			if (!this.hasGeneratedVideo) {
				uni.showToast({
					title: '请先生成视频',
					icon: 'none',
					duration: 2000
				});
				return;
			}

			// 确保显示生成的视频
			if (!this.isShowingGeneratedVideo && this.hasGeneratedVideo) {
				this.toggleGeneratedVideo();
				// 短暂延迟后直接调用分享
				setTimeout(() => {
					this.shareVideo();
				}, 300);
			} else {
				// 直接调用分享方法
				this.shareVideo();
			}
		},

		// ========== 图片缓存相关方法 ==========

		/**
		 * 获取缓存的图片URL，没有缓存时返回默认图片
		 */
		getCachedImageUrl() {
			try {
				// 首先尝试从当前状态获取
				if (this.uploadedImageUrl) {
					return this.uploadedImageUrl;
				}

				// 从缓存中获取
				const cachedImageUrl = uni.getStorageSync(this.imageCacheKey);
				if (cachedImageUrl) {
					this.uploadedImageUrl = cachedImageUrl;
					return cachedImageUrl;
				}

				// 都没有时返回默认图片
				return this.defaultImageUrl;
			} catch (error) {
				console.error('[图片缓存] 获取缓存图片失败:', error);
				return this.defaultImageUrl;
			}
		},

		/**
		 * 从缓存中加载上传的图片
		 */
		loadUploadedImageFromCache() {
			try {
				const cachedImageUrl = uni.getStorageSync(this.imageCacheKey);
				if (cachedImageUrl) {
					this.uploadedImageUrl = cachedImageUrl;
					console.log('[图片缓存] 从缓存中加载上传的图片:', cachedImageUrl);
				} else {
					console.log('[图片缓存] 没有缓存图片，将使用默认图片');
				}
			} catch (error) {
				console.error('[图片缓存] 加载缓存图片失败:', error);
			}
		},

		/**
		 * 保存上传的图片到缓存
		 */
		saveUploadedImageToCache(imageUrl) {
			try {
				uni.setStorageSync(this.imageCacheKey, imageUrl);
				this.uploadedImageUrl = imageUrl;
				console.log('[图片缓存] 图片URL已保存到缓存:', imageUrl);

				// 触发界面更新
				this.$forceUpdate();
			} catch (error) {
				console.error('[图片缓存] 保存图片URL到缓存失败:', error);
			}
		},

		/**
		 * 清除图片缓存
		 */
		clearImageCache() {
			try {
				uni.removeStorageSync(this.imageCacheKey);
				this.uploadedImageUrl = '';
				console.log('[图片缓存] 图片缓存已清除');
			} catch (error) {
				console.error('[图片缓存] 清除图片缓存失败:', error);
			}
		},

		// 初始化视频播放器
		initVideoPlayer() {
			console.log('[AI视频详情] 初始化视频播放器');
			try {
				this.videoContext = uni.createVideoContext('main-video', this);
				console.log('[AI视频详情] 视频上下文创建成功');

				// 延迟预加载视频 - 使用增强版本
				setTimeout(() => {
					this.enhancedPreloadVideo();
				}, 300); // 缩短延迟，提前开始预加载

			} catch (error) {
				console.error('[AI视频详情] 视频播放器初始化失败:', error);
				uni.showToast({
					title: '视频播放器初始化失败',
					icon: 'error',
					duration: 3000
				});
			}
		},

		// 预加载视频
		async preloadVideo() {
			try {
				console.log('[AI视频详情] 开始预加载视频:', this.currentVideoUrl);
				this.isVideoLoading = true;

				// 检查网络状态
				if (this.networkType === 'none') {
					console.warn('[AI视频详情] 无网络连接，跳过预加载');
					this.isVideoLoading = false;
					uni.showToast({
						title: '网络连接失败',
						icon: 'error',
						duration: 3000
					});
					return;
				}

				// 在非WiFi环境下，直接使用原URL，不进行缓存
				if (!this.isWifiConnected) {
					console.log('[AI视频详情] 非WiFi环境，直接播放');
					this.isVideoLoading = false;
					return;
				}

				// 只在WiFi环境下进行视频缓存
				try {
					const cachedUrl = await this.videoCache.cache(this.currentVideoUrl, {
						priority: 1,
						size: '未知'
					});

					if (cachedUrl && cachedUrl !== this.currentVideoUrl) {
						this.currentVideoUrl = cachedUrl;
						console.log('[AI视频详情] 视频预加载完成，使用缓存地址:', cachedUrl);
					} else {
						console.log('[AI视频详情] 使用原始视频地址');
					}
				} catch (cacheError) {
					console.warn('[AI视频详情] 视频缓存失败，使用原始地址:', cacheError);
				}

				this.isVideoLoading = false;

			} catch (error) {
				console.error('[AI视频详情] 视频预加载失败:', error);
				this.isVideoLoading = false;

				// 显示错误提示
				uni.showToast({
					title: '视频加载失败',
					icon: 'error',
					duration: 3000
				});
			}
		},

		// 播放视频
		playVideo() {
			if (this.videoContext) {
				this.videoContext.play();
			}
		},

		// 暂停视频
		pauseVideo() {
			if (this.videoContext) {
				this.videoContext.pause();
			}
		},

		/**
		 * 上传照片 - 点击头像选择拍照或相册
		 */
		async uploadPhoto() {
			try {
				// 添加触觉反馈
				uni.vibrateShort({
					type: 'light'
				});

				// 显示选择方式弹窗
				const actionResult = await new Promise((resolve, reject) => {
					uni.showActionSheet({
						itemList: ['拍照', '从相册选择'],
						success: resolve,
						fail: reject
					});
				});

				// 处理图片选择
				this.handleImageSelection(actionResult.tapIndex);
			} catch (error) {
				// 用户取消选择
				if (error.errMsg && error.errMsg.includes('cancel')) {
					return;
				}

				console.error('显示选择弹窗失败:', error);
				uni.showToast({
					title: '操作失败，请重试',
					icon: 'error',
					duration: 2000
				});
			}
		},

		/**
		 * 处理图片选择
		 */
		async handleImageSelection(tapIndex) {
			try {
				// 根据选择设置来源类型
				let sourceType = ['album'];
				if (tapIndex === 0) {
					sourceType = ['camera'];
				}

				// 调用封装的上传方法
				const uploadResult = await chooseAndUploadImage({
					count: 1,
					sourceType: sourceType,
					onProgress: (progress) => {
						console.log('上传进度:', progress + '%');
					}
				});

				if (uploadResult && uploadResult.success) {
					// 保存上传的图片URL
					this.uploadedImageUrl = uploadResult.data.url;

					// 保存到缓存
					this.saveUploadedImageToCache(this.uploadedImageUrl);

					// 显示成功提示
					uni.showToast({
						title: '照片上传成功！',
						icon: 'success',
						duration: 2000
					});

				} else {
					// 上传失败
					const errorMsg = uploadResult ? uploadResult.error : '上传失败';
					uni.showToast({
						title: errorMsg,
						icon: 'error',
						duration: 3000
					});
				}
			} catch (error) {
				console.error('上传照片失败:', error);

				// 用户取消选择
				if (error.errMsg && error.errMsg.includes('cancel')) {
					return;
				}

				// 其他错误
				uni.showToast({
					title: '操作失败，请重试',
					icon: 'error',
					duration: 3000
				});
			}
		},
		async submitFusionTask() {
			console.log('[AI视频详情] submitFusionTask 参数 modelId:', this.modelId, 'uploadedImageUrl:', this.uploadedImageUrl)
			if (!this.modelId) {
				uni.showToast({ title: '缺少modelId参数', icon: 'error' })
				return
			}
			if (!this.uploadedImageUrl) {
				uni.showToast({ title: '请先上传照片', icon: 'error' })
				return
			}
			this.loading = true
			this.statusText = '正在提交融合任务...'
			const res = await submitVideoFusion({
				source_image: this.uploadedImageUrl,
				model_id: this.modelId
			})
			if (res.success && res.data && res.data.job_id) {
				this.jobId = res.data.job_id
				this.statusText = '任务已提交，正在排队...'
				this.pollFusionStatus()
			} else {
				this.loading = false
				this.statusText = '任务提交失败'
				uni.showToast({ title: res.error || '提交失败', icon: 'error' })
			}
		},
		pollFusionStatus() {
			if (!this.jobId) return
			this.statusText = '正在处理视频...'
			this.loading = true // 确保loading状态为true，显示加载提示

			let pollCount = 0;
			const maxPollCount = 20; // 3秒一次，最多1分钟
			this.pollingTimer = setInterval(async () => {
				pollCount++;
				const res = await getVideoFusionStatus({ job_id: this.jobId })
				if (res.success && res.data) {
					const status = res.data.status
					console.log('[AI视频详情] 任务状态:', res.data)

					// 根据不同状态显示不同提示文本
					if (status === 1 || status === '排队中') {
						this.statusText = `排队中...已等待${pollCount * 3}秒`
					} else if (status === 3 || status === '处理中') {
						this.statusText = `视频融合处理中...已等待${pollCount * 3}秒`
					} else if (status === 7 || status === '处理完成') {
						clearInterval(this.pollingTimer)
						this.loading = false

						// 视频融合完成，开始添加水印
						const originalVideoUrl = res.data.video_url || ''
						if (originalVideoUrl) {
							console.log('[AI视频详情] 视频融合完成，开始添加水印:', originalVideoUrl)
							await this.addWatermarkToGeneratedVideo(originalVideoUrl)
						} else {
							// 如果没有视频URL，直接完成
							this.statusText = '处理完成！'
							this.generatedVideoUrl = originalVideoUrl
							this.hasGeneratedVideo = true
							this.saveVideoUrlToCache(this.generatedVideoUrl)

							uni.showModal({
								title: '处理完成',
								content: '视频生成成功！点击右侧按钮查看生成视频',
								showCancel: false
							})
						}
					} else if (status === 5 || status === '处理失败') {
						clearInterval(this.pollingTimer)
						this.loading = false
						this.statusText = '处理失败：' + (res.data.error_message || '未知错误')
						// 使用Modal替代Toast，确保用户能看到
						uni.showModal({
							title: '处理失败',
							content: res.data.error_message || '视频融合失败',
							showCancel: false
						})
					}
				}
				if (pollCount >= maxPollCount) {
					clearInterval(this.pollingTimer)
					this.loading = false
					this.statusText = '处理超时，请稍后重试'
					uni.showModal({
						title: '处理超时',
						content: '请稍后重试',
						showCancel: false
					})
				}
			}, 3000)
		},

		/**
		 * 为生成的视频添加水印
		 * @param {string} originalVideoUrl - 原始视频URL
		 */
		async addWatermarkToGeneratedVideo(originalVideoUrl) {
			try {
				console.log('[视频水印] 开始为生成的视频添加水印:', originalVideoUrl)

				this.isAddingWatermark = true
				this.showWatermarkProgress = true
				this.watermarkProgressText = '正在添加水印...'

				// 初始化水印服务
				if (!videoWatermarkService.isInitialized) {
					await videoWatermarkService.init()
				}

				// 构建水印配置 - 使用预设的logo+文字水印
				const watermarkOptions = videoWatermarkService.getWatermarkPreset('logo-with-text')

				// 自定义水印内容
				watermarkOptions.textWatermark.content = '驴小拍AI视频'
				watermarkOptions.textWatermark.fontColor = '0xFF6B35' // 橙色

				// 如果有logo图片水印，设置URL
				if (watermarkOptions.imageWatermark) {
					watermarkOptions.imageWatermark.url = 'https://cdn.zhzfpn.cn/logo-watermark.png'
				}

				console.log('[视频水印] 使用水印配置:', watermarkOptions)

				// 调用水印服务
				const watermarkResult = await videoWatermarkService.addWatermarkToVideo(
					originalVideoUrl,
					watermarkOptions
				)

				if (watermarkResult.success) {
					// 水印添加成功
					this.watermarkedVideoUrl = watermarkResult.data.outputVideo
					this.generatedVideoUrl = this.watermarkedVideoUrl // 使用带水印的视频
					this.hasGeneratedVideo = true
					this.watermarkJobId = watermarkResult.data.jobId

					// 保存到缓存
					this.saveVideoUrlToCache(this.watermarkedVideoUrl)

					this.statusText = '处理完成！已添加水印'
					this.watermarkProgressText = '水印添加成功！'

					console.log('[视频水印] 水印添加成功:', this.watermarkedVideoUrl)

					// 显示成功提示
					uni.showModal({
						title: '处理完成',
						content: '视频生成成功并已添加品牌水印！点击右侧按钮查看生成视频',
						showCancel: false
					})

				} else {
					// 水印添加失败，使用原视频
					console.warn('[视频水印] 水印添加失败，使用原视频:', watermarkResult.error)

					this.generatedVideoUrl = originalVideoUrl
					this.hasGeneratedVideo = true
					this.saveVideoUrlToCache(this.generatedVideoUrl)
					this.statusText = '视频生成完成（水印添加失败）'
					this.watermarkProgressText = '水印添加失败'

					// 显示警告提示
					uni.showModal({
						title: '视频生成完成',
						content: `视频生成成功，但水印添加失败：${watermarkResult.error}。您可以查看生成的视频。`,
						showCancel: false
					})
				}

			} catch (error) {
				console.error('[视频水印] 添加水印过程出错:', error)

				// 出错时使用原视频
				this.generatedVideoUrl = originalVideoUrl
				this.hasGeneratedVideo = true
				this.saveVideoUrlToCache(this.generatedVideoUrl)
				this.statusText = '视频生成完成（水印添加出错）'
				this.watermarkProgressText = '水印添加出错'

				uni.showModal({
					title: '视频生成完成',
					content: `视频生成成功，但水印添加过程中出现错误：${error.message}。您可以查看生成的视频。`,
					showCancel: false
				})

			} finally {
				this.isAddingWatermark = false
				// 延迟隐藏水印进度提示
				setTimeout(() => {
					this.showWatermarkProgress = false
				}, 2000)
				this.loading = false
			}
		},

		// 生成AI视频
		async generateAIVideo() {
			if (this.isGenerating || this.loading) return;
			this.isGenerating = true;
			await this.submitFusionTask();
			this.isGenerating = false;
		},

		// 模拟AI视频生成过程
		async simulateAIVideoGeneration() {
			// 模拟生成时间
			await new Promise(resolve => setTimeout(resolve, 3000));

			// 使用原视频作为结果（实际项目中这里会调用AI视频生成接口）
			this.resultVideoUrl = this.currentVideoUrl;

			// 显示结果
			this.showGenerationResult({
				success: true,
				data: {
					result_video: this.resultVideoUrl
				}
			});
		},

		// 显示生成结果
		showGenerationResult(result) {
			console.log('[AI视频详情] 处理生成结果:', result);

			if (result && result.success) {
				// 生成成功
				const resultVideoUrl = result.data.result_video;

				if (resultVideoUrl) {
					this.resultVideoUrl = resultVideoUrl;
					this.openResultModal();
				} else {
					uni.showToast({
						title: '视频结果获取失败',
						icon: 'error',
						duration: 3000
					});
				}
			} else {
				// 生成失败
				const errorMsg = result && result.error ? result.error : '视频生成失败';
				uni.showToast({
					title: errorMsg,
					icon: 'error',
					duration: 3000
				});
			}
		},

		// 显示结果弹窗
		openResultModal() {
			uni.showToast({
				title: 'AI视频生成成功！',
				icon: 'success',
				duration: 2000
			});

			this.showResultModal = true;
		},

		// 关闭结果弹窗
		closeResultModal() {
			this.showResultModal = false;
			this.resultVideoUrl = '';
		},

		// 预览视频
		previewVideo() {
			if (!this.resultVideoUrl) {
				uni.showToast({
					title: '视频地址无效',
					icon: 'error',
					duration: 2000
				});
				return;
			}

			console.log('[AI视频详情] 预览视频:', this.resultVideoUrl);
			// 在小程序中，视频预览功能由video组件本身提供
		},

		// 分享视频
		shareVideo() {
			console.log('[视频分享] 开始分享视频');
			console.log('[视频分享] 可用视频URL检查:');
			console.log('- resultVideoUrl:', this.resultVideoUrl);
			console.log('- generatedVideoUrl:', this.generatedVideoUrl);
			console.log('- currentVideoUrl:', this.currentVideoUrl);

			// 按优先级选择视频URL
			let shareVideoUrl = this.resultVideoUrl;

			if (!shareVideoUrl) {
				console.log('[视频分享] resultVideoUrl为空，尝试使用generatedVideoUrl');
				shareVideoUrl = this.generatedVideoUrl;
			}

			if (!shareVideoUrl) {
				console.log('[视频分享] generatedVideoUrl也为空，尝试使用currentVideoUrl');
				shareVideoUrl = this.currentVideoUrl;
			}

			console.log('[视频分享] 最终使用的视频URL:', shareVideoUrl);

			if (!shareVideoUrl) {
				console.error('[视频分享] 错误: 所有视频URL变量均为空!');
				uni.showToast({
					title: '视频地址无效',
					icon: 'error',
					duration: 2000
				});
				return;
			}

			// 设置分享标记，以便在onShow中显示奖励弹窗
			uni.setStorageSync('videoShared', true);
			console.log('[视频分享] 已设置分享标记 videoShared=true');

			// 显示分享提示
			uni.showToast({
				title: '请选择要分享的好友',
				icon: 'none',
				duration: 2000
			});

			// 保存要分享的视频URL，以便在onShareAppMessage中使用
			this.$data.shareVideoUrl = shareVideoUrl;

			console.log('[视频分享] 准备分享，等待用户选择好友');
		},

		// 下载视频到相册
		async downloadVideo() {
			if (!this.videoUrl) {
				uni.showToast({
					title: '没有可下载的视频',
					icon: 'none'
				});
				return;
			}

			if (this.isDownloading) {
				uni.showToast({
					title: '正在下载中，请稍候',
					icon: 'none'
				});
				return;
			}

			try {
				this.isDownloading = true;

				// 显示下载中提示
				uni.showLoading({
					title: '下载中...',
					mask: true
				});

				// 下载视频到临时路径
				const downloadResult = await new Promise((resolve, reject) => {
					uni.downloadFile({
						url: this.videoUrl,
						success: resolve,
						fail: reject
					});
				});

				if (downloadResult.statusCode === 200) {
					// 检查保存到相册的权限
					const authResult = await new Promise((resolve) => {
						uni.authorize({
							scope: 'scope.writePhotosAlbum',
							success: () => resolve(true),
							fail: () => resolve(false)
						});
					});

					if (!authResult) {
						uni.hideLoading();
						this.isDownloading = false;
						// 引导用户开启权限
						uni.showModal({
							title: '提示',
							content: '需要保存到相册权限，请在设置中开启',
							confirmText: '去设置',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting();
								}
							}
						});
						return;
					}

					// 保存到相册
					await new Promise((resolve, reject) => {
						uni.saveVideoToPhotosAlbum({
							filePath: downloadResult.tempFilePath,
							success: resolve,
							fail: reject
						});
					});

					uni.hideLoading();
					uni.showToast({
						title: '视频已保存到相册',
						icon: 'success'
					});
				} else {
					throw new Error('下载失败，状态码：' + downloadResult.statusCode);
				}
			} catch (error) {
				console.error('[AI视频详情] 视频下载失败:', error);
				uni.hideLoading();
				uni.showModal({
					title: '下载失败',
					content: '视频下载或保存失败，请重试',
					showCancel: false
				});
			} finally {
				this.isDownloading = false;
			}
		},

		// 全屏预览视频
		previewVideoFullscreen() {
			if (!this.videoUrl) {
				uni.showToast({
					title: '视频未加载完成',
					icon: 'none'
				});
				return;
			}

			// 使用uni.previewMedia API预览视频
			uni.previewMedia({
				sources: [{
					url: this.videoUrl,
					type: 'video',
					poster: ''  // 可以设置视频封面
				}],
				current: 0,
				success: () => {
					console.log('[AI视频详情] 全屏预览成功');
					uni.showToast({
						title: '长按可保存视频',
						icon: 'none',
						duration: 2000
					});
				},
				fail: (err) => {
					console.error('[AI视频详情] 全屏预览失败:', err);
					// 降级处理：如果API不支持，使用系统视频播放器
					this.previewVideoFallback();
				}
			});
		},

		// 全屏预览降级处理
		previewVideoFallback() {
			// 创建临时视频上下文
			const videoContext = uni.createVideoContext('preview-video');
			if (videoContext && videoContext.requestFullScreen) {
				videoContext.requestFullScreen();
			} else {
				// 如果API不支持，显示提示
				uni.showModal({
					title: '提示',
					content: '当前设备不支持全屏预览，请直接点击视频进行播放',
					showCancel: false
				});
			}
		},

		// ========== 主视频播放事件处理 ==========

		onMainVideoLoadStart() {
			console.log('[AI视频详情] 主视频开始加载');
			this.isVideoLoading = true;

			// 设置加载超时
			setTimeout(() => {
				if (this.isVideoLoading) {
					console.warn('[AI视频详情] 视频加载超时');
					this.isVideoLoading = false;
					uni.showToast({
						title: '视频加载超时，请检查网络',
						icon: 'none',
						duration: 3000
					});
				}
			}, 10000); // 10秒超时
		},

		onMainVideoCanPlay() {
			console.log('[AI视频详情] 主视频可以播放');
			this.isVideoLoading = false;
		},

		onMainVideoPlay() {
			console.log('[AI视频详情] 主视频开始播放');
			this.isPlaying = true;
		},

		onMainVideoPause() {
			console.log('[AI视频详情] 主视频暂停');
			this.isPlaying = false;
		},

		onMainVideoTimeUpdate(event) {
			// 视频播放进度更新
			// console.log('[AI视频详情] 播放进度:', event.detail);
		},

		onMainVideoEnded() {
			console.log('[AI视频详情] 主视频播放结束');
			this.isPlaying = false;
		},

		onMainVideoError(event) {
			console.error('[AI视频详情] 主视频播放错误:', event.detail);
			this.isVideoLoading = false;
			this.isPlaying = false;

			uni.showToast({
				title: '视频加载失败',
				icon: 'error',
				duration: 3000
			});
		},

		onMainVideoFullscreenChange(event) {
			console.log('[AI视频详情] 全屏状态变化:', event.detail);
		},

		// ========== 小程序网络检测 ==========

		/**
		 * 检测小程序网络状态
		 */
		async detectNetworkStatus() {
			try {
				const networkInfo = await uni.getNetworkType();
				this.networkType = networkInfo.networkType;
				this.isWifiConnected = networkInfo.networkType === 'wifi';

				console.log(`[AI视频详情] 当前网络: ${this.networkType}`);

				// 监听网络状态变化
				uni.onNetworkStatusChange((res) => {
					this.networkType = res.networkType;
					this.isWifiConnected = res.networkType === 'wifi';
					console.log(`[AI视频详情] 网络变化: ${res.networkType}`);
				});

			} catch (error) {
				console.warn('[AI视频详情] 网络检测失败:', error);
			}
		},

		// 从缓存加载视频URL
		loadVideoUrlFromCache() {
			try {
				// 从本地存储获取视频URL缓存
				const cachedData = uni.getStorageSync('videoUrlCache');
				if (cachedData) {
					this.videoUrlCache = JSON.parse(cachedData);

					// 检查当前模板ID是否有缓存的视频URL
					if (this.modelId && this.videoUrlCache[this.modelId]) {
						this.videoUrl = this.videoUrlCache[this.modelId].url;
						this.currentVideoUrl = this.videoUrl;
						console.log('[AI视频详情] 从缓存加载视频URL成功:', this.videoUrl);

						// 显示提示
						uni.showToast({
							title: '已加载上次生成的视频',
							icon: 'none',
							duration: 2000
						});
					}
				}
			} catch (error) {
				console.error('[AI视频详情] 加载缓存视频URL失败:', error);
			}
		},

		// 保存视频URL到缓存
		saveVideoUrlToCache(url) {
			try {
				if (!this.modelId || !url) return;

				// 从本地存储获取现有缓存
				let cachedData = uni.getStorageSync('videoUrlCache');
				let videoUrlCache = {};

				if (cachedData) {
					videoUrlCache = JSON.parse(cachedData);
				}

				// 更新缓存
				videoUrlCache[this.modelId] = {
					url: url,
					timestamp: Date.now()
				};

				// 保存回本地存储
				uni.setStorageSync('videoUrlCache', JSON.stringify(videoUrlCache));
				this.videoUrlCache = videoUrlCache;

				console.log('[AI视频详情] 视频URL已保存到缓存:', this.modelId, url);
			} catch (error) {
				console.error('[AI视频详情] 保存视频URL到缓存失败:', error);
			}
		},

		// ========== 自动播放和抖音式交互 ==========

		/**
		 * 开始自动播放
		 */
		async startAutoPlay() {
			if (this.hasAutoPlayed || !this.autoPlayEnabled) {
				return;
			}

			// 检查网络条件
			if (!this.shouldAutoPlay()) {
				console.log('[自动播放] 网络条件不适合自动播放');
				return;
			}

			try {
				console.log('[自动播放] 开始自动播放视频:', this.currentVideoUrl);

				// 确保视频已预加载
				await this.preloadVideo();

				// 启动播放
				if (this.videoContext) {
					this.videoContext.play();
					this.hasAutoPlayed = true;

					// 友好的提示
					setTimeout(() => {
						uni.showToast({
							title: '视频已开始播放',
							icon: 'none',
							duration: 1500
						});
					}, 500);
				}

			} catch (error) {
				console.error('[自动播放] 自动播放失败:', error);
			}
		},

		/**
		 * 强制播放视频（用于视频切换）
		 */
		async forcePlayVideo() {
			try {
				console.log('[强制播放] 开始播放视频:', this.currentVideoUrl);

				// 等待一帧，确保DOM已更新
				await this.$nextTick();

				// 重新初始化视频播放器
				this.videoContext = uni.createVideoContext('main-video', this);

				// 等待视频播放器初始化完成
				await new Promise(resolve => setTimeout(resolve, 200));

				// 强制启动播放
				if (this.videoContext) {
					// 先确保视频停止
					this.videoContext.stop();

					// 等待停止完成
					await new Promise(resolve => setTimeout(resolve, 100));

					// 开始播放
					this.videoContext.play();
					this.isPlaying = true;

					console.log('[强制播放] 视频开始播放:', this.currentVideoUrl);

					// 显示切换提示
					uni.showToast({
						title: '视频已切换',
						icon: 'none',
						duration: 1000
					});
				}

			} catch (error) {
				console.error('[强制播放] 播放失败:', error);

				// 如果强制播放失败，尝试备用方案
				this.fallbackVideoPlay();
			}
		},

		/**
		 * 备用播放方案
		 */
		fallbackVideoPlay() {
			console.log('[备用播放] 尝试备用播放方案');

			setTimeout(() => {
				if (this.videoContext) {
					this.videoContext.play();
					this.isPlaying = true;
				}
			}, 500);
		},

		/**
		 * 判断是否应该自动播放
		 */
		shouldAutoPlay() {
			// 2G/3G网络不自动播放
			if (['2g', '3g'].includes(this.networkType)) {
				return false;
			}

			// WiFi环境优先自动播放
			if (this.isWifiConnected) {
				return true;
			}

			// 4G/5G环境也可以自动播放
			if (['4g', '5g'].includes(this.networkType)) {
				return true;
			}

			return false;
		},



		/**
		 * 增强的视频预加载
		 */
		async enhancedPreloadVideo() {
			try {
				// 如果已经在预加载，直接返回
				if (this.isVideoLoading) {
					return;
				}

				console.log('[增强预加载] 开始预加载视频:', this.currentVideoUrl);
				this.isVideoLoading = true;

				// 检查网络状态
				if (this.networkType === 'none') {
					throw new Error('无网络连接');
				}

				// 在WiFi环境下进行视频缓存
				if (this.isWifiConnected && this.videoCache) {
					try {
						const cachedUrl = await this.videoCache.cache(this.currentVideoUrl, {
							priority: 1,
							size: '未知',
							autoPlay: true // 标记为自动播放预加载
						});

						if (cachedUrl && cachedUrl !== this.currentVideoUrl) {
							console.log('[增强预加载] 使用缓存地址:', cachedUrl);
							this.currentVideoUrl = cachedUrl;
						}
					} catch (cacheError) {
						console.warn('[增强预加载] 缓存失败，使用原地址:', cacheError);
					}
				}

				// 添加到预加载队列
				this.addToPreloadQueue(this.currentVideoUrl);

			} catch (error) {
				console.error('[增强预加载] 预加载失败:', error);
				uni.showToast({
					title: '视频加载失败',
					icon: 'none',
					duration: 2000
				});
			} finally {
				this.isVideoLoading = false;
			}
		},

		/**
		 * 添加到预加载队列
		 */
		addToPreloadQueue(videoUrl) {
			if (!this.videoCacheQueue.includes(videoUrl)) {
				this.videoCacheQueue.push(videoUrl);

				// 保持队列大小
				if (this.videoCacheQueue.length > this.maxCacheSize) {
					this.videoCacheQueue.shift();
				}

				console.log('[预加载队列] 当前队列:', this.videoCacheQueue);
			}
		},

		// ========== 抖音式交互方法 ==========

		/**
		 * 切换视频播放/暂停
		 */
		toggleVideoPlay() {
			if (!this.videoContext) {
				console.warn('[视频播放] 视频上下文未初始化');
				return;
			}

			if (this.isPlaying) {
				this.videoContext.pause();
			} else {
				this.videoContext.play();
			}

			// 添加触觉反馈
			uni.vibrateShort({
				type: 'light'
			});
		},



		/**
		 * 切换生成视频和原视频
		 */
		toggleGeneratedVideo() {
			if (!this.hasGeneratedVideo) {
				uni.showToast({
					title: '暂无生成视频',
					icon: 'none',
					duration: 1500
				});
				return;
			}

			// 切换视频状态
			this.isShowingGeneratedVideo = !this.isShowingGeneratedVideo;

			if (this.isShowingGeneratedVideo) {
				// 切换到生成视频
				this.currentVideoUrl = this.generatedVideoUrl;
				uni.showToast({
					title: '正在播放你的换脸视频',
					icon: 'none',
					duration: 1500
				});
			} else {
				// 切换回原视频
				this.currentVideoUrl = this.originalVideoUrl;
				uni.showToast({
					title: '正在播放素材视频',
					icon: 'none',
					duration: 1500
				});
			}

			// 添加触觉反馈
			uni.vibrateShort({
				type: 'light'
			});

			// 重新初始化视频播放器
			this.$nextTick(() => {
				if (this.videoContext) {
					this.videoContext.stop();
					setTimeout(() => {
						this.videoContext.play();
					}, 100);
				}
			});
		},

		/**
		 * 检查是否有缓存的生成视频
		 */
		checkCachedGeneratedVideo() {
			try {
				if (!this.modelId) return;

				const cachedData = uni.getStorageSync('videoUrlCache');
				if (cachedData) {
					const videoUrlCache = JSON.parse(cachedData);
					if (videoUrlCache[this.modelId]) {
						this.generatedVideoUrl = videoUrlCache[this.modelId].url;
						this.hasGeneratedVideo = true;
						console.log('[AI视频详情] 发现缓存的生成视频:', this.generatedVideoUrl);
					}
				}
			} catch (error) {
				console.error('[AI视频详情] 检查缓存生成视频失败:', error);
			}
		},

		/**
		 * 处理生成按钮点击事件
		 */
		handleGenerateClick() {
			// 如果当前播放的是生成的视频，显示村BA代言弹窗
			if (this.isShowingGeneratedVideo) {
				this.showVillageBAModal = true;
			} else {
				// 否则执行原来的生成AI视频逻辑
				this.generateAIVideo();
			}
		},

		/**
		 * 获取生成按钮文字
		 */
		getGenerateButtonText() {
			if (this.isGenerating) {
				return '生成中...';
			}
			if (this.isShowingGeneratedVideo) {
				return '我为村BA代言';
			}
			return '立即生成';
		},

		/**
		 * 关闭村BA代言弹窗
		 */
		closeVillageBAModal() {
			this.showVillageBAModal = false;
		},

		/**
		 * 设置村BA活动图片路径
		 */
		setVillageBAImagePath() {
			// 获取当前页面路径作为参考
			const pages = getCurrentPages();
			const currentPage = pages[pages.length - 1];
			console.log('当前页面路径:', currentPage.route);

			// 使用本地图片路径
			this.villageBAImagePath = 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png';
			console.log('设置村BA活动图片路径:', this.villageBAImagePath);
		},

		/**
		 * 村BA图片加载成功
		 */
		onVillageBAImageLoad(e) {
			console.log('村BA活动图片加载成功', e);
			console.log('图片路径:', this.villageBAImagePath);
			this.villageBAImageLoadFailed = false;
		},

		/**
		 * 村BA图片加载失败
		 */
		onVillageBAImageError(e) {
			console.log('村BA活动图片加载失败', e);
			console.log('尝试的图片路径:', this.villageBAImagePath);
			this.villageBAImageLoadFailed = true;
			// 尝试其他路径
			this.tryAlternativeVillageBAImagePaths();
		},

		/**
		 * 尝试其他村BA图片路径
		 */
		tryAlternativeVillageBAImagePaths() {
			console.log('尝试其他村BA图片路径...');
			// 尝试不同的路径格式
			const paths = [
				'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png',
				'.https://cdn.zhzfpn.cn/PicGo/20250830221404597.png',
				'..https://cdn.zhzfpn.cn/PicGo/20250830221404597.png',
				'../..https://cdn.zhzfpn.cn/PicGo/20250830221404597.png',
				'/static/images/village-ba.png'
			];

			// 随机尝试一个新路径
			const randomPath = paths[Math.floor(Math.random() * paths.length)];
			console.log('尝试新村BA图片路径:', randomPath);
			this.villageBAImagePath = randomPath;
		},

		/**
		 * 支付代言村BA
		 */
		endorseVillageBA() {
			console.log('点击支付代言村BA');

			// 显示支付确认弹窗
			uni.showModal({
				title: '村BA代言确认',
				content: '支付9.9元成为村BA代言人，并分享到朋友圈参与活动赢取大奖？',
				confirmText: '立即支付',
				cancelText: '取消',
				success: (res) => {
					if (res.confirm) {
						this.processVillageBAPayment();
					}
				}
			});
		},

		/**
		 * 处理村BA代言支付流程
		 */
		processVillageBAPayment() {
			console.log('开始处理村BA代言支付');

			// 显示支付加载状态
			uni.showLoading({
				title: '正在支付...',
				mask: true
			});

			// 模拟支付过程（这里需要集成真实的支付接口）
			setTimeout(() => {
				uni.hideLoading();

				// 支付成功后分享到朋友圈
				this.shareVillageBAToMomentsAfterPayment();
			}, 2000);
		},

		/**
		 * 支付成功后分享到朋友圈
		 */
		shareVillageBAToMomentsAfterPayment() {
			// 分享到微信朋友圈
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneTimeline',
				type: 1,
				title: '我为村BA代言 - AI视频换脸',
				summary: '支付9.9元成为村BA代言人，参与活动赢取大奖！',
				imageUrl: this.villageBAImagePath || 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png',
				success: (res) => {
					console.log('村BA代言支付后分享朋友圈成功:', res);
					this.hasEndorsed = true;

					// 显示成功提示和奖励信息
					uni.showModal({
						title: '代言成功',
						content: '恭喜您！支付成功并完成分享，已成功成为村BA代言人，现在可以参与活动赢取大奖！',
						showCancel: false,
						confirmText: '开始参与',
						success: () => {
							// 关闭分享弹窗
							this.closeVillageBAModal();

							// 显示欢迎提示
							uni.showToast({
								title: '欢迎成为村BA代言人！',
								icon: 'success',
								duration: 2000
							});
						}
					});
				},
				fail: (err) => {
					console.error('村BA代言支付后分享朋友圈失败:', err);

					// 支付成功但分享失败的处理
					uni.showModal({
						title: '支付成功',
						content: '支付已成功，但分享失败。您仍已成为村BA代言人，请稍后手动分享获取更多奖励。',
						showCancel: false,
						confirmText: '继续参与',
						success: () => {
							this.hasEndorsed = true;
							this.closeVillageBAModal();

							uni.showToast({
								title: '欢迎成为村BA代言人！',
								icon: 'success',
								duration: 2000
							});
						}
					});
				}
			});
		},



		/**
		 * 重置视频状态
		 */
		resetVideoStates() {
			// 停止当前视频
			if (this.videoContext) {
				this.videoContext.stop();
			}

			// 重置播放状态
			this.isPlaying = false;
			this.hasAutoPlayed = false;

			// 重置生成相关状态
			this.isGenerating = false;
			this.loading = false;
			this.hasGeneratedVideo = false;
			this.isShowingGeneratedVideo = false;
			this.generatedVideoUrl = '';

			// 重置弹窗状态
			this.showResultModal = false;
			this.showVillageBAModal = false;
			this.resultVideoUrl = '';

			// 重置村BA代言状态
			this.hasEndorsed = false;

			// 清理定时器
			if (this.pollingTimer) {
				clearInterval(this.pollingTimer);
				this.pollingTimer = null;
			}

			// 重置状态文本
			this.statusText = '';
		},

		/**
		 * 更新头像边框显示
		 */
		updateAvatarBorder() {
			// 如果用户已经上传了照片，显示绿色边框
			return this.uploadedImageUrl ? 'avatar-uploaded' : '';
		},
		saveQrcode() {
			// 保存二维码到相册的逻辑
			console.log('保存二维码到相册');
		},
		closeRewardDialog() {
			this.showRewardDialog = false;
		},
		// 分享成功回调
		onShareSuccess() {
			console.log('视频分享成功，设置分享标记');
			uni.setStorageSync('videoShared', true);

			// 可以在这里添加分享成功后的逻辑
			uni.showToast({
				title: '分享成功',
				icon: 'success',
				duration: 1500
			});
		},

		// 保存二维码到相册
		saveQrcode() {
			uni.showLoading({
				title: '保存中...'
			});

			// 检查授权状态
			uni.getSetting({
				success: (res) => {
					if (res.authSetting['scope.writePhotosAlbum']) {
						// 已授权，直接保存
						this.downloadAndSaveImage();
					} else {
						// 未授权，请求授权
						uni.authorize({
							scope: 'scope.writePhotosAlbum',
							success: () => {
								// 授权成功，保存图片
								this.downloadAndSaveImage();
							},
							fail: (err) => {
								uni.hideLoading();
								console.error('授权失败:', err);

								// 用户拒绝授权，引导用户打开设置页面
								uni.showModal({
									title: '提示',
									content: '保存图片需要您授权保存到相册的权限',
									confirmText: '去设置',
									cancelText: '取消',
									success: (res) => {
										if (res.confirm) {
											uni.openSetting({
												success: (settingRes) => {
													console.log('设置页面返回:', settingRes);
													if (settingRes.authSetting['scope.writePhotosAlbum']) {
														// 用户在设置页面授权了，重新保存
														this.downloadAndSaveImage();
													}
												}
											});
										}
									}
								});
							}
						});
					}
				},
				fail: (err) => {
					uni.hideLoading();
					console.error('获取授权状态失败:', err);
					uni.showToast({
						title: '获取授权状态失败',
						icon: 'none',
						duration: 2000
					});
				}
			});
		},

		// 下载并保存图片
		downloadAndSaveImage() {
			// 先下载网络图片到本地临时路径
			uni.downloadFile({
				url: this.qrcodeImage,
				success: (res) => {
					if (res.statusCode === 200) {
						// 下载成功，保存到相册
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: () => {
								uni.hideLoading();
								this.showSaveSuccess = true;

								// 3秒后隐藏保存成功提示
								setTimeout(() => {
									this.showSaveSuccess = false;
								}, 3000);
							},
							fail: (err) => {
								uni.hideLoading();
								console.error('保存图片失败:', err);

								uni.showToast({
									title: '保存图片失败',
									icon: 'none',
									duration: 2000
								});
							}
						});
					} else {
						uni.hideLoading();
						console.error('下载图片失败，状态码:', res.statusCode);

						uni.showToast({
							title: '下载图片失败',
							icon: 'none',
							duration: 2000
						});
					}
				},
				fail: (err) => {
					uni.hideLoading();
					console.error('下载图片失败:', err);

					uni.showToast({
						title: '下载图片失败',
						icon: 'none',
						duration: 2000
					});
				}
			});
		}
	},

	computed: {
		// 村BA活动图片URL
		villageBAActivityImageUrl() {
			// 在不同平台使用不同的路径格式
			// #ifdef H5
			return 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png';
			// #endif
			// #ifdef MP-WEIXIN
			return 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png';
			// #endif
			// #ifdef APP-PLUS
			return 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png';
			// #endif
			return 'https://cdn.zhzfpn.cn/PicGo/20250830221404597.png';
		}
	},

	// 添加 onShareAppMessage 生命周期函数，与 methods 同级
	onShareAppMessage(res) {
		console.log('触发视频分享', res);

		// 设置分享标记
		uni.setStorageSync('videoShared', true);

		// 选择要分享的视频URL
		const shareVideoUrl = this.resultVideoUrl || this.generatedVideoUrl || this.currentVideoUrl;

		// 构建分享标题
		const shareTitle = `我用AI换脸生成了一段视频，快来体验吧！`;

		// 构建分享路径
		const sharePath = '/pages/ai-trip/index/index?source=videofusion';

		return {
			title: shareTitle,
			path: sharePath,
			imageUrl: '', // 可以添加一个视频封面图
			success: () => {
				console.log('分享成功');
				this.onShareSuccess();
			},
			fail: (err) => {
				console.log('视频分享失败', err);
			}
		}
	}
}
</script>

<style scoped>
/* ========== 抖音式全屏视频容器 ========== */
.douyin-video-container {
	width: 100vw;
	height: 100vh;
	position: relative;
	background: #000;
	overflow: hidden;
}

/* ========== 卡片式滑动容器与卡片 ========== */
.video-swiper-wrapper {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	will-change: transform;
}

.video-slide {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

.current-slide {
	z-index: 3;
}

.prev-slide {
	z-index: 2;
	transform: translateY(-100%);
}

.next-slide {
	z-index: 2;
	transform: translateY(100%);
}

.preview-video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* ========== 全屏视频背景 ========== */
.fullscreen-video {
	width: 100%;
	height: 100%;
	object-fit: cover;
	position: absolute;
	top: 0;
	left: 0;
	z-index: 1;
}

/* ========== 左上角返回按钮 ========== */
/* 导航栏样式调整 - 原返回按钮样式已移除 */



/* ========== 右侧操作栏 ========== */
.right-sidebar {
	position: absolute;
	right: 40rpx;
	bottom: 180rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 40rpx;
	z-index: 1000;
}

/* ========== 生成视频按钮 ========== */
.generated-video-button {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8rpx;
	margin-bottom: 20rpx;
	transition: all 0.3s ease;
}

.generated-video-button:active {
	transform: scale(0.9);
}

/* ========== 右侧分享按钮已删除 ========== */

.video-button-icon {
	width: 100rpx;
	height: 100rpx;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 3rpx solid rgba(255, 255, 255, 0.8);
	box-shadow:
		0 8rpx 24rpx rgba(102, 126, 234, 0.4),
		0 4rpx 12rpx rgba(102, 126, 234, 0.2);
}

.video-icon {
	font-size: 40rpx;
	color: white;
	font-weight: bold;
}

.video-button-text {
	font-size: 22rpx;
	color: white;
	text-align: center;
	font-weight: 500;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

/* ========== 用户头像容器 ========== */
.avatar-container {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 20rpx;
	margin: -20rpx;
	cursor: pointer;
	transition: all 0.3s ease;
	z-index: 1001;
}

.user-avatar {
	width: 100rpx;
	height: 100rpx;
	border-radius: 50%;
	border: 4rpx solid rgba(255, 255, 255, 0.8);
	transition: all 0.3s ease;
}

.avatar-container:active .user-avatar {
	transform: scale(0.9);
}

.avatar-border {
	position: absolute;
	top: -4rpx;
	left: -4rpx;
	right: -4rpx;
	bottom: -4rpx;
	border: 4rpx solid transparent;
	border-radius: 50%;
	background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
	background-size: 300% 300%;
	animation: gradientShift 3s ease infinite;
	z-index: -1;
}

@keyframes gradientShift {
	0% {
		background-position: 0% 50%;
	}

	50% {
		background-position: 100% 50%;
	}

	100% {
		background-position: 0% 50%;
	}
}

.upload-plus {
	position: absolute;
	bottom: -10rpx;
	right: -10rpx;
	width: 40rpx;
	height: 40rpx;
	background: #ff4757;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: white;
	font-size: 32rpx;
	font-weight: bold;
	border: 4rpx solid white;
	box-shadow: 0 4rpx 12rpx rgba(255, 71, 87, 0.4);
}

/* ========== 右侧操作按钮 ========== */
.action-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8rpx;
	transition: all 0.3s ease;
}

.action-item:active {
	transform: scale(0.9);
}

.action-icon-container {
	width: 100rpx;
	height: 100rpx;
	background: rgba(0, 0, 0, 0.3);
	backdrop-filter: blur(20rpx);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2rpx solid rgba(255, 255, 255, 0.2);
}

.action-item .action-icon {
	font-size: 48rpx;
	color: white;
}

.action-text {
	font-size: 24rpx;
	color: white;
	text-align: center;
	font-weight: 500;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

/* ========== 底部视频信息区域 ========== */
.bottom-info {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
	padding: 40rpx 30rpx;
	padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
	z-index: 50;
}

.video-info {
	margin-bottom: 30rpx;
	padding-right: 140rpx;
	/* 为右侧操作栏留出空间 */
}

.video-title {
	font-size: 32rpx;
	font-weight: 600;
	color: white;
	line-height: 1.4;
	margin-bottom: 10rpx;
	text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.7);
}

.video-subtitle {
	font-size: 28rpx;
	color: rgba(255, 255, 255, 0.9);
	line-height: 1.4;
	margin-bottom: 20rpx;
	text-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.5);
}

.video-meta {
	display: flex;
	align-items: center;
	gap: 20rpx;
}

.video-author {
	font-size: 24rpx;
	color: rgba(255, 255, 255, 0.8);
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

.video-duration {
	font-size: 24rpx;
	color: rgba(255, 255, 255, 0.8);
	background: rgba(0, 0, 0, 0.3);
	padding: 6rpx 12rpx;
	border-radius: 12rpx;
	backdrop-filter: blur(10rpx);
}

/* ========== 立即生成按钮 ========== */
.generate-button {
	background: linear-gradient(135deg, #7ed321 0%, #56bf47 100%);
	color: white;
	padding: 24rpx 60rpx;
	border-radius: 50rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow:
		0 8rpx 24rpx rgba(126, 211, 33, 0.4),
		0 4rpx 12rpx rgba(126, 211, 33, 0.2);
	transition: all 0.3s ease;
	border: 2rpx solid rgba(255, 255, 255, 0.1);
}

.generate-button:active {
	transform: translateY(2rpx) scale(0.98);
	box-shadow:
		0 6rpx 18rpx rgba(126, 211, 33, 0.5),
		0 3rpx 9rpx rgba(126, 211, 33, 0.3);
}

.generate-button.generating {
	background: linear-gradient(135deg, #999 0%, #666 100%);
	box-shadow:
		0 8rpx 24rpx rgba(153, 153, 153, 0.4),
		0 4rpx 12rpx rgba(153, 153, 153, 0.2);
	pointer-events: none;
}

.generate-text {
	font-size: 32rpx;
	font-weight: 600;
	letter-spacing: 2rpx;
}

/* ========== 视频加载状态覆盖层 ========== */
.video-loading-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	z-index: 60;
}

.loading-spinner {
	width: 80rpx;
	height: 80rpx;
	border: 4rpx solid rgba(255, 255, 255, 0.2);
	border-top: 4rpx solid #ffffff;
	border-radius: 50%;
	animation: spin 1.2s linear infinite;
	margin-bottom: 30rpx;
}

@keyframes spin {
	0% {
		transform: rotate(0deg);
	}

	100% {
		transform: rotate(360deg);
	}
}

.loading-text {
	font-size: 28rpx;
	color: #ffffff;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

/* ========== 播放/暂停提示器 ========== */
.play-pause-indicator {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	z-index: 40;
	transition: all 0.3s ease;
}

.play-pause-indicator:active {
	transform: translate(-50%, -50%) scale(0.9);
}

.play-icon-large {
	width: 140rpx;
	height: 140rpx;
	background: rgba(0, 0, 0, 0.6);
	backdrop-filter: blur(20rpx);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: white;
	font-size: 60rpx;
	border: 3rpx solid rgba(255, 255, 255, 0.3);
	box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.3);
}

/* ========== 处理状态提示 ========== */
.fusion-loading {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: rgba(0, 0, 0, 0.8);
	backdrop-filter: blur(20rpx);
	padding: 60rpx 80rpx;
	border-radius: 30rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	z-index: 999;
	min-width: 400rpx;
	border: 2rpx solid rgba(255, 255, 255, 0.1);
}

.status-text {
	color: #fff;
	font-size: 32rpx;
	margin-top: 30rpx;
	text-align: center;
	font-weight: 500;
}

/* ========== 结果弹窗样式 ========== */
.result-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.95);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
	backdrop-filter: blur(20rpx);
}

.result-modal-content {
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	background: #000;
	border-radius: 0;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.result-modal-header {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 40rpx 60rpx;
	background: rgba(0, 0, 0, 0.9);
	border-bottom: 2rpx solid rgba(255, 255, 255, 0.1);
}

.result-modal-title {
	font-size: 40rpx;
	font-weight: 600;
	color: #7ed321;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

.result-modal-body {
	flex: 1;
	display: flex;
	justify-content: center;
	align-items: center;
	background: #000;
}

.result-video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.result-modal-footer {
	padding: 40rpx 60rpx;
	background: rgba(0, 0, 0, 0.9);
	display: flex;
	justify-content: space-around;
	gap: 40rpx;
	border-top: 2rpx solid rgba(255, 255, 255, 0.1);
}

.share-btn,
.close-btn {
	flex: 1;
	padding: 28rpx 60rpx;
	border-radius: 50rpx;
	font-size: 32rpx;
	font-weight: 600;
	border: none;
	transition: all 0.3s ease;
	background: linear-gradient(135deg, #7ed321 0%, #56bf47 100%);
	color: white;
	box-shadow: 0 8rpx 24rpx rgba(126, 211, 33, 0.3);
}

.share-btn:active,
.close-btn:active {
	transform: translateY(2rpx) scale(0.98);
	box-shadow: 0 6rpx 18rpx rgba(126, 211, 33, 0.4);
}

/* ========== 村BA代言弹窗样式 ========== */
.village-ba-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
	backdrop-filter: blur(10rpx);
	-webkit-backdrop-filter: blur(10rpx);
	padding: 60rpx 40rpx;
}

.village-ba-modal-content {
	width: 100%;
	height: 100%;
	max-width: 700rpx;
	height: calc(75vh + 400rpx);
	max-height: 90vh;
	position: relative;
	background: transparent;
	border-radius: 24rpx;
	overflow: hidden;
	box-shadow: 0 24rpx 60rpx rgba(0, 0, 0, 0.3);
	animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
	from {
		transform: scale(0.9);
		opacity: 0;
	}

	to {
		transform: scale(1);
		opacity: 1;
	}
}

.village-ba-image-container {
	position: relative;
	width: 100%;
	height: 100%;
	background: transparent;
	display: flex;
	align-items: center;
	justify-content: center;
}

.village-ba-image {
	width: 100%;
	height: 100%;
	display: block;
	border-radius: 24rpx;
	background: transparent;
}

.village-ba-placeholder {
	width: 100%;
	height: 100%;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 24rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.placeholder-text {
	color: white;
	font-size: 48rpx;
	font-weight: bold;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
}

.village-ba-buttons-group {
	position: absolute;
	bottom: 40rpx;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	justify-content: center;
	z-index: 11;
	width: calc(100% - 40rpx);
}

.village-ba-button {
	background: linear-gradient(135deg, #ff6b35 0%, #ff8f42 100%);
	color: white;
	padding: 24rpx 30rpx;
	border-radius: 50rpx;
	font-size: 24rpx;
	font-weight: 600;
	box-shadow: 0 12rpx 32rpx rgba(255, 107, 53, 0.4);
	transition: all 0.3s ease;
	cursor: pointer;
	backdrop-filter: blur(10rpx);
	-webkit-backdrop-filter: blur(10rpx);
	text-align: center;
	line-height: 1.4;
	width: 100%;
}

.village-ba-button.endorsement-button {
	background: linear-gradient(135deg, #4CAF50 0%, #66BB6A 100%);
	box-shadow: 0 12rpx 32rpx rgba(76, 175, 80, 0.4);
}

.village-ba-button:active {
	transform: scale(0.95);
	box-shadow: 0 8rpx 24rpx rgba(76, 175, 80, 0.6);
}

.village-ba-text {
	color: white;
	font-weight: 600;
}

.highlight-text {
	color: #ffeb3b;
	font-weight: 700;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3);
}

.village-ba-close-button {
	position: absolute;
	top: 90rpx;
	left: 5rpx;
	width: 60rpx;
	height: 60rpx;
	background: rgba(0, 0, 0, 0.6);
	color: white;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 32rpx;
	font-weight: 300;
	z-index: 11;
	backdrop-filter: blur(10rpx);
	-webkit-backdrop-filter: blur(10rpx);
	transition: all 0.3s ease;
}

.village-ba-close-button:active {
	transform: scale(0.95);
	background: rgba(0, 0, 0, 0.7);
}

.village-ba-close-text {
	color: white;
	font-size: 40rpx;
	line-height: 1;
}

/* ========== 安全区域适配 ========== */
@supports (bottom: env(safe-area-inset-bottom)) {
	.bottom-info {
		padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
	}

	.right-sidebar {
		bottom: calc(180rpx + env(safe-area-inset-bottom));
	}
}



/* ========== 水印处理状态提示 ========== */
.watermark-loading {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: rgba(0, 0, 0, 0.85);
	backdrop-filter: blur(20rpx);
	padding: 60rpx 80rpx;
	border-radius: 30rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	z-index: 1001;
	min-width: 400rpx;
	border: 2rpx solid rgba(255, 107, 53, 0.4);
	box-shadow: 0 20rpx 40rpx rgba(255, 107, 53, 0.2);
}

.watermark-spinner {
	border-top-color: #FF6B35 !important;
	border-right-color: rgba(255, 107, 53, 0.3) !important;
	border-bottom-color: rgba(255, 107, 53, 0.3) !important;
	border-left-color: rgba(255, 107, 53, 0.3) !important;
}

.watermark-tip {
	color: rgba(255, 255, 255, 0.8);
	font-size: 24rpx;
	margin-top: 20rpx;
	text-align: center;
	line-height: 1.4;
}

/* ========== 抖音式视频界面样式结束 ========== */

/* 奖励弹窗样式 */
.dialog-mask {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.6);
	z-index: 999;
}

.dialog-content {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 80%;
	background-color: #fff;
	border-radius: 12px;
	padding: 30px 20px;
	z-index: 1000;
	box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

.dialog-title {
	font-size: 18px;
	font-weight: bold;
	text-align: center;
	margin-bottom: 20px;
	color: #333;
}

.reward-content {
	padding-bottom: 20px;
}

.qrcode-container {
	width: 200px;
	height: 200px;
	margin: 0 auto 20px;
	border: 1px solid #eee;
	padding: 10px;
	border-radius: 8px;
	background-color: #fff;
}

.qrcode-image {
	width: 100%;
	height: 100%;
}

.coupon-info {
	margin-bottom: 20px;
	padding: 0 10px;
}

.coupon-code,
.coupon-expire {
	font-size: 14px;
	color: #666;
	margin-bottom: 5px;
	text-align: center;
}

.coupon-desc {
	font-size: 12px;
	color: #999;
	text-align: center;
	margin-top: 10px;
}

.dialog-buttons {
	display: flex;
	justify-content: space-around;
}

.save-btn {
	background: linear-gradient(135deg, #4CAF50, #2E8B57);
	color: white;
	border: none;
	padding: 10px 30px;
	border-radius: 30px;
	font-size: 14px;
}

.close-btn {
	background-color: #f5f5f5;
	color: #666;
	border: 1px solid #ddd;
	padding: 10px 30px;
	border-radius: 30px;
	font-size: 14px;
}

/* 保存成功提示 */
.save-success {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background-color: rgba(0, 0, 0, 0.7);
	color: white;
	padding: 15px 30px;
	border-radius: 30px;
	z-index: 1001;
}

.success-content {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.success-content .iconfont {
	font-size: 24px;
	margin-bottom: 5px;
}

.success-text {
	font-size: 14px;
}

.play-icon-image {
	width: 60rpx;
	height: 60rpx;
}

/* 自定义按钮样式已删除 */
</style>